package com.ssm.controller;

import com.alibaba.fastjson.JSONObject;
import com.ssm.service.ServiceInfoService;
import com.ssm.unity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * Created by wtjr on 2018/1/4.
 */
@Controller
@RequestMapping("service")
public class ServiceInfoController {

    @Autowired
    ServiceInfoService serviceInfoService;

    @RequestMapping(value = "serviceInfo", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject nearbyServiceInfo(String user_uuid, HttpServletRequest request) {
        ResponseResult result = new ResponseResult();
        HashMap disposeResult = new HashMap();
        result.setCurrentVersion();

        //调用isRegisted方法来验证是否是注册用户
        List list = serviceInfoService.queryNearServiceInfos(user_uuid);

        if (list.isEmpty() || list == null) {
            result.setStatusCode("failure");
            result.setInvoking("0004");
            result.setMessage("周边暂时没有服务站点");
        } else {
            result.setStatusCode("success");
            result.setInvoking("0000");
            result.setMessage("登录成功");

            HashMap map = new HashMap();
            map.put("serviceList", list);
            result.setDisposeResult(map);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        return jsonObject;
    }
}
